﻿<Window 
    x:Class="Dispatcher.Views.EventEditControl"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:converters="clr-namespace:Dispatcher.Converters"
    xmlns:repository="clr-namespace:Repository;assembly=Repository"
    WindowStartupLocation="CenterOwner"
    Title="Событие" 
    Height="700" Width="366">
    <Window.Resources>

        <converters:EventTooltipConverter x:Key="EventTooltipConverter"/>
        <converters:PersonShortNameConverter x:Key="PersonShortNameConverter"/>
        <converters:PersonFullNameConverter x:Key="PersonFullNameConverter"/>
        <converters:VisibilityTrueConverter x:Key="VisibilityTrueConverter"/>
        <converters:VisibilityFalseConverter x:Key="VisibilityFalseConverter"/>
        <converters:TimeRangeConverter x:Key="TimeRangeConverter"/>
        <converters:ShortTimeConverter x:Key="ShortTimeConverter"/>

        <DataTemplate DataType = "{x:Type repository:Person}">
            <Grid AllowDrop="True">
                <StackPanel Orientation="Horizontal">
                    <TextBlock 
                        Text="{Binding Converter={StaticResource PersonShortNameConverter}}"
                        ToolTip="{Binding Converter={StaticResource PersonFullNameConverter}}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate DataType = "{x:Type repository:EventGroup}">
            <Grid AllowDrop="True">
                <StackPanel Orientation="Horizontal">
                    <TextBlock Text="{Binding Path=Name}"/>
                </StackPanel>
            </Grid>
        </DataTemplate>

        <DataTemplate x:Key="ComboBoxItemTemplate">
            <StackPanel Orientation="Horizontal">
                <CheckBox IsChecked="{Binding IsChecked}" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked">
                    <StackPanel Orientation="Horizontal" Width="200">
                        <TextBlock Text="{Binding Path=Name}" ToolTip="{Binding Path=Description}"  Width="Auto"/>
                    </StackPanel>
                </CheckBox>
            </StackPanel>
        </DataTemplate>
        
        <Style TargetType="{x:Type GroupBox}">
            <Setter Property="Margin" Value="4"/>
        </Style>

    </Window.Resources>

    <StackPanel VerticalAlignment="Stretch">

        <GroupBox Header="Организатор">
            <ComboBox Margin="5" Name="Combo2" ItemsSource="{Binding Path=OrganizePersons}" SelectedItem="{Binding SelectedOrganizePerson, Mode=TwoWay}" IsReadOnly="True"/>
        </GroupBox>

        <GroupBox Header="Время">
            <StackPanel>
                <ComboBox Grid.Column="1" Grid.Row="0" Margin="5" ItemsSource="{Binding Pairs}" SelectedItem="{Binding SelectedPair}">
                    <ComboBox.ItemTemplate>
                        <DataTemplate>
                            <StackPanel Orientation="Horizontal">
                                <TextBlock Text="{Binding Name, StringFormat='{}{0} '}"/>
                                <TextBlock Text="{Binding Converter={StaticResource TimeRangeConverter}}"/>
                            </StackPanel>
                        </DataTemplate>
                    </ComboBox.ItemTemplate>
                </ComboBox>
                <StackPanel Grid.Column="1" Grid.Row="2" Orientation="Horizontal">
                    <TextBox Margin="5" Text="{Binding StartTime, Mode=TwoWay, Converter={StaticResource ShortTimeConverter}}" Width="50"/>
                    <TextBlock VerticalAlignment="Center">-</TextBlock>
                    <TextBox Margin="5" Text="{Binding EndTime, Mode=TwoWay, Converter={StaticResource ShortTimeConverter}}"  Width="50"/>
                    <CheckBox Margin="5" IsChecked="{Binding IsSingle, Mode=TwoWay}" VerticalAlignment="Center" Content="Единожды"/>
                    <DatePicker SelectedDate="{Binding SingleDate, Mode=TwoWay}" Margin="5" />
                </StackPanel>
            </StackPanel>
        </GroupBox>
        
        <!--<ComboBox Visibility="Collapsed" Margin="5" ItemTemplate="{StaticResource ComboBoxItemTemplate}" Name="Combo3" ItemsSource="{Binding Path=ModelContainer.EquipmentTypeSet}" IsEditable="True" IsReadOnly="True" Text="Выберите участников..."/>-->

        <GroupBox Header="Переодичность" Name="PeriodGroup"  Grid.Row="7" Visibility="{Binding IsSingle, Converter={StaticResource VisibilityFalseConverter}}">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="Auto"/>
                </Grid.ColumnDefinitions>
                <TextBlock Margin="6" Grid.Row="0" Grid.Column="0" Text="Недели"/>
                <TextBlock Margin="6" Grid.Row="1" Grid.Column="0" Text="Начало периода"/>
                <TextBlock Margin="6" Grid.Row="2" Grid.Column="0" Text="Конец периода"/>
                <ComboBox Grid.Column="1" Grid.Row="0" Margin="5" ItemTemplate="{StaticResource ComboBoxItemTemplate}" Name="Combo4" ItemsSource="{Binding Path=Weeks}" IsEditable="True" IsReadOnly="True" Text="Выберите недели..."/>
                <DatePicker Grid.Column="1" Grid.Row="1" Margin="5" SelectedDate="{Binding PeriodStart, Mode=TwoWay}"/>
                <DatePicker Grid.Column="1" Grid.Row="2" Margin="5" SelectedDate="{Binding PeriodEnd, Mode=TwoWay}"/>
            </Grid>
        </GroupBox>

        <GroupBox Header="Тип">
            <ComboBox Margin="5" Name="Combo1" ItemsSource="{Binding Path=ClassTypes}" SelectedItem="{Binding SelectedClassType, Mode=TwoWay}" SelectedIndex="0" IsReadOnly="True"/>
        </GroupBox>
        
        <GroupBox Header="Описание">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto"/>
                    <RowDefinition Height="Auto"/>
                </Grid.RowDefinitions>

                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto"/>
                    <ColumnDefinition Width="*"/>
                </Grid.ColumnDefinitions>

                <TextBlock Margin="5" Grid.Row="0" Grid.Column="0" Text="Тема"/>
                <TextBlock Margin="5" Grid.Row="1" Grid.Column="0" Text="Примечания"/>
                <TextBox Margin="5" Grid.Row="0" Grid.Column="1" Text="{Binding Name, Mode=TwoWay}" AcceptsReturn="True"/>
                <TextBox Margin="5" Grid.Row="1" Grid.Column="1" Text="{Binding Description, Mode=TwoWay}" AcceptsReturn="True" Height="40"/>
            </Grid>
        </GroupBox>
        
        <StackPanel Margin="5"  Orientation="Horizontal" HorizontalAlignment="Right">
            <Button Margin="5" Width="77" Command="Save" Click="OkButton_Click">Ok</Button>
            <Button Margin="5" Width="77" Click="CancedlButton_Click">Cancel</Button>
        </StackPanel>

        <GroupBox Header="Пересекающиеся события" VerticalAlignment="Stretch">
            <ScrollViewer Height="100">
            <ListBox Margin="4" ItemsSource="{Binding CrossedEvents}">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <TextBlock Text="{Binding Converter={StaticResource EventTooltipConverter}}"/>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox></ScrollViewer>
        </GroupBox>
    </StackPanel>
</Window>
